package com.webserver.http;

import com.sun.deploy.panel.IProperty;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 当前类用于定义那些在Http协议中规定内容，以便进行复用
 */
public class HttpContext {
    /**
     * 回车符
     */
    public static final char CR = 13;
    /**
     * 换行符
     */
    public static final char LF = 10;
    /**
     * MIME类型映射
     * key：资源的后缀名，如：css，png，html等等
     * value：该资源类型对应的MIME值：如：text/css,image/png,text/html等等
     */
    private static Map<String,String> mineMapping = new HashMap<>();
    static {
        initMiMeMapping();
    }
    private static void initMiMeMapping(){
        try {
            Properties properties = new Properties();
            properties.load(
                    HttpContext.class.getResourceAsStream("web.properties")
            );
            properties.forEach((k,v)->mineMapping.put(k.toString(),v.toString()));
            System.out.println(properties.size());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println(getMineType("mp3"));
    }
    public static String getMineType(String ext){
        return mineMapping.get(ext);
    }



}
